package com.lemei.cn.myokhttpbeen.ui.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemei.cn.myokhttpbeen.R;
import com.lemei.cn.myokhttpbeen.adpter.MyViewPagerAdpter;
import com.lemei.cn.myokhttpbeen.been.FragmentInforBeen;
import com.lemei.cn.myokhttpbeen.ui.fragment.HomeFragment;
import com.lemei.cn.myokhttpbeen.ui.fragment.SubjectFragment;
import com.lemei.cn.myokhttpbeen.utils.Utils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @Bind(R.id.vp_main_show_layout)
    ViewPager      vpMainShowLayout;
    @Bind(R.id.image_photo)
    ImageView      imagePhoto;
    @Bind(R.id.image_over)
    ImageView      imageOver;
    @Bind(R.id.user_name)
    TextView       userName;
    @Bind(R.id.user_email)
    TextView       userEmail;
    @Bind(R.id.photo_layout)
    RelativeLayout photoLayout;
    @Bind(R.id.activity_main)
    DrawerLayout   activityMain;
    @Bind(R.id.tab_main_titles)
    TabLayout      tabMainTitles;
    private ActionBarDrawerToggle mToggle;
    private List<FragmentInforBeen> mList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        initActionbar();

        initViewPager();

    }

    private void initViewPager() {
//        for (int i = 0; i < 5; i++) {
//            mList.add(new FragmentInforBeen(new HomeFragment(),"美女"+i));
//        }

        String[] stringArray = Utils.getStringArray(R.array.tab_names);


            mList.add(new FragmentInforBeen(new HomeFragment(),stringArray[0]));
            mList.add(new FragmentInforBeen(new SubjectFragment(),stringArray[1]));
            mList.add(new FragmentInforBeen(new HomeFragment(),stringArray[2]));
            mList.add(new FragmentInforBeen(new HomeFragment(),stringArray[3]));
            mList.add(new FragmentInforBeen(new HomeFragment(),stringArray[4]));

        vpMainShowLayout.setAdapter(new MyViewPagerAdpter(getSupportFragmentManager(), mList));
        //设置联动
        tabMainTitles.setupWithViewPager(vpMainShowLayout);

    }

    private void initActionbar() {
        ActionBar actionBar = getSupportActionBar();

        actionBar.setTitle("谷歌json解析和网络请求框架");


        //显示箭头
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDefaultDisplayHomeAsUpEnabled(true);

        //箭头联动
        mToggle = new ActionBarDrawerToggle(this, activityMain, R.string.open, R.string.close);

        //同步
        mToggle.syncState();
        //设置点击监听
        activityMain.addDrawerListener(mToggle);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case android.R.id.home:
                mToggle.onOptionsItemSelected(item);
                break;
        }


        return super.onOptionsItemSelected(item);
    }
}
